#include <iostream>
#include <string>

using namespace std;

class stu
{
private:
    int val;

public:
    int *ptr;

public:
    stu() : val(10)
    {
    }
    stu(int val , int ptr_val) : 
        val(val) , ptr(new int(ptr_val))
    {

    }

    // 深拷贝
    stu(const stu &other)
    {
        cout << "调用拷贝构造函数" << endl;
        if (NULL == other.ptr)
        {
            // 如果传入是null 直接赋值
            ptr = other.ptr;
        }
        else
        {
            // 如果传入的不是null 则 需要将值取出 并重新 创建空间
            ptr = new int(*other.ptr);
        }

        val = other.val;
    }

    ~stu()
    {
        if(NULL != ptr)
        {
            cout << "调用析构 释放空间完成" << endl;
            delete ptr;  
        }

    }

public:
    void show()
    {
        cout << val << endl;
        cout << *ptr << endl;
    }


public:
    // 超纲了后面会讲
    // const stu &operator=(const stu &other)
    // {
    //     cout << "调用了等于号" << endl;
    // }
};

int main(int argc, char const *argv[])
{
    stu s1(10 , 20);

    stu s2(s1);
    *s1.ptr = 90;
    s2.show();

    return 0;
}